package gulimall.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serializable;

import gulimall.valid.AddGroup;
import gulimall.valid.ListValue;
import gulimall.valid.UpdateGroup;
import gulimall.valid.UpdateShowStatusGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.URL;

import javax.validation.Valid;
import javax.validation.constraints.*;

/**
 * <p>
 * 品牌
 * 1.@NotEmpty 用在集合类上面
 * 2.@NotBlank 用在String上面
 * 3.@NotNull 用在基本类型上
 *
 * @author HLF
 * @since 2022-04-23
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("pms_brand")
public class Brand implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 品牌id
     */
    @TableId(value = "brand_id", type = IdType.AUTO)
    @Null(message = "新增操作不能指定品牌id", groups = {AddGroup.class})//表示在添加操作时，品牌id必须为null
    @NotNull(message = "修改操作必须指定品牌id", groups = {UpdateGroup.class})
    private Long brandId;

    /**
     * 品牌名
     * 仅当新增时品牌名不能为空，修改时不修改品牌名的话就不用携带该参数，可以为空
     */
    @NotBlank(message = "品牌名不能为空！", groups = {AddGroup.class})
    private String name;

    /**
     * 品牌logo地址
     */
    @URL(message = "品牌logo地址格式不正确！", groups = {AddGroup.class, UpdateGroup.class})
    @NotBlank(message = "品牌logo地址不能为空！", groups = {AddGroup.class})
    private String logo;

    /**
     * 介绍
     */
    @NotBlank(message = "品牌介绍不能为空！", groups = {AddGroup.class})
    private String descript;

    /**
     * 显示状态[0-不显示；1-显示]
     * 使用自定义校验注解
     */
    @ListValue(values = {0, 1},
            message = "显示状态必须为0[不显示]或1[显示]",
            groups = {AddGroup.class, UpdateShowStatusGroup.class}
    )
    @NotNull(groups = {AddGroup.class, UpdateShowStatusGroup.class}, message = "显示状态不能为空！")
    private Integer showStatus;

    /**
     * 检索首字母
     */
    @Pattern(regexp = "[a-zA-Z]", message = "检索首字母必须为单个字母", groups = {AddGroup.class, UpdateGroup.class})
    @NotBlank(message = "检索首字母不能为空！", groups = {AddGroup.class})
    private String firstLetter;

    /**
     * 排序
     */
    @NotNull(message = "排序字段不能为空！", groups = {AddGroup.class})
    @Min(value = 0, message = "排序字段只能为大于等于0的整数！", groups = {AddGroup.class, UpdateGroup.class})
    private Integer sort;

}
